﻿using blackhouse.AsyncMail.Web;
using blackhouse.BlackApart.Business;
using blackhouse.BlackApart.Business.Reservations;
using blackhouse.mojoPortalExtend;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;

namespace blackhouse.StareKino.QuartzActions.ASyncMails {
    public class ReservationMailTemplate : ASyncHtmlMailTemplate {

        #region Fields

        private IWebReservation reservation;
        private int siteId = 1;

        #endregion

        #region Properties

        protected IWebReservation Reservation {
            get {
                if (this.reservation == null)
                    this.reservation = Factory.Instance().GetWebReservation((this.BindObject as ReservationClientMailActionData).ReservationId);
                return this.reservation;
            }
        }

        protected int SiteId {
            get {
                return this.siteId;
            }
        }

        #endregion

        #region Methods

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            if (this.Reservation.Client != null && !String.IsNullOrEmpty(this.Reservation.Client.PrefferLanguage)) {
                CultureInfo clientLanguage = CultureInfo.GetCultureInfo(this.Reservation.Client.PrefferLanguage);
                Thread.CurrentThread.CurrentCulture = clientLanguage;
                Thread.CurrentThread.CurrentUICulture = clientLanguage;

                this.siteId = clientLanguage.GetSiteId();
            }
        }

        #endregion

    }
}